var status = -1;
var selectionLog = [];

function start() {
    action(1, 0, 0)
}

function action(f, d, c) {
    if (status == 0 && f == 0) {
        im.dispose();
        return
    }(f == 1) ? status++ : status--;
    selectionLog[status] = c;
    var a = -1;
    if (status <= a++) {
        im.dispose()
    } else {
        if (status === a++) {
            var e = [1082707, 1082708, 1082709, 1082710, 1082711];
            var b = randomNum(0, 100);
            im.gainItem(im.getItemId(), -1);
            if (b < 1) {
                im.gainItemPeriod(e[0], 1, randomNum(3, 7))
            } else {
                if (b < 10) {
                    im.gainItemPeriod(e[1], 1, randomNum(3, 7))
                } else {
                    if (b < 25) {
                        im.gainItemPeriod(e[2], 1, randomNum(3, 7))
                    } else {
                        if (b < 50) {
                            im.gainItemPeriod(e[3], 1, randomNum(3, 7))
                        } else {
                            im.gainItemPeriod(e[4], 1, randomNum(3, 7))
                        }
                    }
                }
            }
            im.dispose()
        } else {
            im.dispose()
        }
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
};